#include <algorithm>
#include <iostream>
#include <vector>

#define ENDL '\n'
using std::cin;
using std::cout;
using std::vector;

bool judge(vector<int> &a, vector<int> &b, int n) {
  for (int i = 1; i <= n; ++i) {
    if (a[i] != b[i]) {
      return false;
    }
  }
  return true;
};

void trans(vector<int> &a, int n) {
  if (n % 2 == 0) {
    for (int i = 1; i <= n / 2; ++i) {
      std::swap(a[i], a[n + 1 - i]);
    }
  } else {
    for (int i = 2; i <= n / 2 + 1; ++i) {
      std::swap(a[i], a[n + 2 - i]);
    }
  }
};

void move(vector<int> &a, int n) {
  int last = a[n];
  for (int i = n; i >= 2; --i)
    a[i] = a[i - 1];
  a[1] = last;
};
void solve() {
  int n;
  cin >> n;
  vector<int> a(n + 1);
  vector<int> b(n + 1);

  for (int i = 1; i <= n; ++i)
    cin >> a[i];
  for (int i = 1; i <= n; ++i)
    cin >> b[i];

  bool ans = false;

  for (int i = 0; i < n; ++i) {
    if (judge(a, b, n)) {
      ans = true;
      break;
    }
    move(a, n);
  }

  if (!ans) {
    // 翻转后检查所有旋转情况
    trans(a, n);
    for (int i = 0; i < n; ++i) {
      if (judge(a, b, n)) {
        ans = true;
        break;
      }
      move(a, n);
    }
  }
  cout << (ans ? "YES" : "NO") << ENDL;
}

int main() {
  int T = 1;
  cin >> T;
  while (T--) {
    solve();
  }
  return 0;
}